package com.example.administrator.myapplication.Presenter;

import com.example.administrator.myapplication.Bean.AjaxResult;
import com.example.administrator.myapplication.Bean.User;
import com.example.administrator.myapplication.Model.ILogonModel;
import com.example.administrator.myapplication.Model.LogonModel;
import com.example.administrator.myapplication.View.Activity.ILogonView;

/**
 * Created by Administrator on 2019/10/6 0006.
 */

public class LogonPresenter implements ILogonPresenter,ILogonListener{
    private ILogonView iLogonView;
    private ILogonModel iLogonModel;
    public LogonPresenter(ILogonView iLogonView){
        this.iLogonView = iLogonView;
        this.iLogonModel = new LogonModel();
    }
    @Override
    public void success(AjaxResult ajaxResult) {
        if(ajaxResult.getCode()==AjaxResult.SUCCESS_CODE)
            iLogonView.showSuccess(ajaxResult.getMsg());
        else
            iLogonView.showError(ajaxResult.getMsg());
    }

    @Override
    public void fail(String error) {
        iLogonView.showError(error);
    }

    @Override
    public void LoginNameUnique(String ret) {
        if (ret.equals("1"))
            iLogonView.showLoginNameNotUnique();
        else
            iLogonView.showLoginNameIsUnique();
    }

    @Override
    public void PhoneUnique(String ret) {
        if (ret.equals("1"))
            iLogonView.showPhoneNotUnique();
        else
            iLogonView.showPhoneIsUnique();
    }

    @Override
    public void EmailUnique(String ret) {
        if (ret.equals("1"))
            iLogonView.showEmailNotUnique();
        else
            iLogonView.showEmailIsUnique();
    }

    @Override
    public void logon(User user) {
        iLogonModel.logon(user,this);
    }

    @Override
    public void checkPhoneUnique(String phonenumber) {
        iLogonModel.checkPhoneUnique(phonenumber,this);
    }

    @Override
    public void checkLoginNameUnique(String loginName) {
         iLogonModel.checkLoginNameUnique(loginName,this);
    }

    @Override
    public void checkEmailUnique(String email) {
         iLogonModel.checkEmailUnique(email,this);
    }
}
